//
//  UIBarButtonItem+Button.swift
//  Weibo201655
//
//  Created by pro on 16/5/6.
//  Copyright © 2016年 LeeDan. All rights reserved.
//

import Foundation
import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(imgName: String) {
        let btn = UIButton()
        
        btn.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imgName + "_highlighted"), forState: UIControlState.Highlighted)
        
        btn.sizeToFit()
        // 便利构造函数必须调用指定构造函数
        self.init(customView: btn)
    }
    
    //类方法
    class func barButtonItem(imgName: String)->UIBarButtonItem {
        
        let btn = UIButton()
        
        btn.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        btn.setImage(UIImage(named: imgName + "_highlighted"), forState: UIControlState.Highlighted)
        
        btn.sizeToFit()
        
        
        return UIBarButtonItem(customView: btn)
    }
    
}